# encoding: UTF-8
require_relative "cultist"
module Napakalaki  
  require "singleton"
  
  class CardDealer
    include Singleton
    
    attr_reader :unused_monsters, :used_monsters, :used_treasures, :unused_treasures, 
      :unused_cultists
    
    def initialize #al ser singleton no se le mete nada
      @unused_monsters = Array.new 
      @used_monsters = Array.new
      @used_treasures = Array.new
      @unused_treasures = Array.new
      @unused_cultists = Array.new
    end
    


    private #METODOS PRIVADOS
    def init_treasure_card_deck
      
      #¡Sí mi amo!
      nuevo = Treasure.new("¡Sí mi amo!", 0, 4, 7, :HELMET)
      @unused_treasures << nuevo   
      
      #Botas de investigación
      nuevo = Treasure.new("Botas de investigación", 600, 3, 4, :BOTHHAND)
      @unused_treasures << nuevo

      #Capucha de Cthulhu
      nuevo = Treasure.new("Capucha de Cthulhu", 500, 3, 5, :HELMET)
      @unused_treasures << nuevo

      #A prueba de babas
      nuevo = Treasure.new("A prueba de babas", 400, 2, 5, :ARMOR)
      @unused_treasures << nuevo
      
      #Botas de lluvia ácida
      nuevo = Treasure.new("Botas de lluvia ácida", 800, 1, 1, :BOTHHAND)
      @unused_treasures << nuevo

      #Casco minero
      nuevo = Treasure.new("Casco minero", 400, 2, 4, :HELMET)
      @unused_treasures << nuevo

      #Ametralladora Thompson
      nuevo =  Treasure.new("Ametralladora Thompson", 600, 4, 8, :BOTHHAND)
      @unused_treasures << nuevo

      #Camiseta de la UGR
      nuevo = Treasure.new("Camiseta de la UGR", 100, 1, 7, :ARMOR)
      @unused_treasures << nuevo

      #Clavo de rail ferroviario
      nuevo = Treasure.new("Clavo de rail ferroviario", 400, 3, 6, :ONEHAND)
      @unused_treasures << nuevo
      
      #Cuchillo de sushi arcano
      nuevo = Treasure.new("Cuchillo de sushi arcano", 300, 2, 3, :ONEHAND)
      @unused_treasures << nuevo

      #Fez alópodo
      nuevo = Treasure.new("Fez alópodo", 700, 3, 5, :HELMET)
      @unused_treasures << nuevo

      #Hacha prehistórica
      nuevo = Treasure.new("Hacha prehistórica", 500, 2, 5, :ONEHAND)
      @unused_treasures << nuevo

      #El aparato del Pr. Tesla
      nuevo = Treasure.new("El aparato del Pr. Tesla", 900, 4, 8, :ARMOR)
      @unused_treasures << nuevo

      #Gaita
      nuevo = Treasure.new("Gaita", 500, 4, 5, :BOTHHAND)
      @unused_treasures << nuevo

      #Insecticida
      nuevo = Treasure.new("Insecticida", 300, 2, 3, :ONEHAND)
      @unused_treasures << nuevo
      
      
      #Escopeta de 3 cañones
      nuevo = Treasure.new("Escopeta de 3 cañones", 700, 4, 6, :BOTHHAND)
      @unused_treasures << nuevo

      #Garabato místico
      nuevo = Treasure.new("Garabato místico", 300, 2, 2, :ONEHAND)
      @unused_treasures << nuevo

      #La fuerza de Mr. T (FALTA HACERLO, NO SE COMO ES BONUS MAYOR)
      #COMO EN RUBY bonus max y min a 0 CONFIRMAR!!!
      nuevo = Treasure.new("La fuerza de Mr. T", 1000, 0, 0, :NECKLACE);
      @unused_treasures << nuevo

      #La rebeca metálica
      nuevo = Treasure.new("La rebeca metálica", 400, 2, 3, :ARMOR)
      @unused_treasures << nuevo

      #Mazo de los antiguos
      nuevo = Treasure.new("Mazo de los antiguos", 200, 3, 4, :ONEHAND)
      @unused_treasures << nuevo

      #Necroplayboycón
      nuevo = Treasure.new("Necroplayboycón", 300, 3, 5, :ONEHAND)
      @unused_treasures << nuevo

      #Lanzallamas
      nuevo = Treasure.new("Lanzallamas", 800, 4, 8, :BOTHHAND)
      @unused_treasures << nuevo
      
      #Necrocomicón
      nuevo = Treasure.new("Necrocomicón", 100, 1, 1, :ONEHAND)
      @unused_treasures << nuevo

      #Necronomicón
      nuevo = Treasure.new("Necronomicón", 800, 5, 7, :BOTHHAND)
      @unused_treasures << nuevo

      #Linterna a 2 manos
      nuevo = Treasure.new("Linterna a 2 manos", 400, 3, 6, :BOTHHAND)
      @unused_treasures << nuevo
       
      #Necrognomicón
      nuevo = Treasure.new("Necrognomicón", 200, 2, 4, :ONEHAND)
      @unused_treasures << nuevo

      #Necrotelecom
      nuevo = Treasure.new("Necrotelecom", 300, 2, 3, :HELMET)
      @unused_treasures << nuevo
       
      #Porra preternatural
      nuevo = Treasure.new("Porra preternatural", 200, 2, 3, :ONEHAND)
      @unused_treasures << nuevo
       
      #Tentáculo de pega
      nuevo = Treasure.new("Tentáculo de pega", 200, 0, 1, :HELMET)
      @unused_treasures << nuevo
       
      #Zapato deja-amigos
      nuevo = Treasure.new("Zapato deja-amigos", 500, 0, 1, :SHOE)
      @unused_treasures << nuevo
       
      #Shogulador
      nuevo = Treasure.new("Shogulador", 600, 1, 1, :BOTHHAND)
      @unused_treasures << nuevo
         
      #Varita de atizamiento
      nuevo = Treasure.new("Varita de atizamiento", 400, 3, 4, :ONEHAND)
      @unused_treasures << nuevo      
    end    
    
    def init_monster_card_deck      
      #defino mal rollo y buen rollo
      bad_stuff = BadStuff.new_death("", false)
      prizes = Prize.new      
      #tipos de visibles
      tvp = Array.new
      top = Array.new
      
      #3 Byakhees de bonanza
      tvp.clear()
      tvp << :ARMOR
      top.clear()       
      top << :ARMOR
      bad_stuff = BadStuff.new_level_specific_treasures("Pierdes tu armadura visible y otra oculta", 0, tvp, top)
      prizes = Prize.new(2, 1);
      @unused_monsters << (Monster.new("3 Byakhees de bonanza", 8, bad_stuff, prizes, 0))

      #Chibithulhu
      tvp.clear()
      tvp << :HELMET
      bad_stuff = BadStuff.new_level_specific_treasures("Embobados con el lindo primigenio te descartas de tu casco visible.", 0, tvp, [])
      prizes = Prize.new(1, 1)
      @unused_monsters << (Monster.new("Chibithulhu", 2, bad_stuff, prizes, 0))
      
      #El sopor de Dunwich
      tvp.clear()
      tvp << :SHOE
      bad_stuff = BadStuff.new_level_specific_treasures("El primordial bostezo contagioso. Pierdes el calzado visible.", 0, tvp, [])
      prizes = Prize.new(1, 1);
      @unused_monsters << (Monster.new("El sopor de Dunwich", 2, bad_stuff, prizes, 0))

      #Ángeles de la noche ibicenca
      tvp.clear()
      tvp << :ONEHAND
      top.clear()
      top << :ONEHAND
      bad_stuff = BadStuff.new_level_specific_treasures("Te atrapan para llevarte de fiesta y te dejan caer en mitad del vuelo. Descarta una mano visible y una mano oculta.", 0, tvp, top)
      prizes = Prize.new(4, 1)
      @unused_monsters << (Monster.new("Ángeles de la noche ibicenca", 14, bad_stuff, prizes, 0))

      #El gorrón en el umbral
      tvp.clear()
      tvp << :ARMOR
      tvp << :BOTHHAND
      tvp << :HELMET
      tvp << :NECKACE
      tvp << :ONEHAND
      tvp << :SHOE
      bad_stuff = BadStuff.new_level_specific_treasures("Pierdes todos tus tesoros visibles.", 0, tvp, [])
      prizes = Prize.new(4, 1)
      @unused_monsters << (Monster.new("El gorrón en el umbral", 10, bad_stuff, prizes, 0))

      #H. P. Munchcraft
      tvp.clear()
      tvp << :ARMOR
      bad_stuff = BadStuff.new_level_specific_treasures("Pierdes la armadura visible.", 0, tvp, [])
      prizes = Prize.new(2, 1);
      @unused_monsters << (Monster.new("H. P. Munchcraft", 6, bad_stuff, prizes, 0))

      #Bichgooth
      tvp.clear()
      tvp << :ARMOR
      bad_stuff = BadStuff.new_level_specific_treasures("Sientes bichos bajo la ropa. Descarta la armadura visible.", 0, tvp, [])
      prizes = Prize.new(1, 1)
      @unused_monsters << (Monster.new("Bichgooth", 2, bad_stuff, prizes, 0))

      #El rey de rosa
      bad_stuff = BadStuff.new_level_number_of_treasures("Pierdes 5 niveles y 3 tesoros visibles.", 5, 3, 0)
      prizes = Prize.new(4, 2)
      @unused_monsters << (Monster.new("El rey de rosa", 13, bad_stuff, prizes, 0))

      #La que redacta en las tinieblas
      bad_stuff = BadStuff.new_level_number_of_treasures("Toses los pulmones y pierdes 2 niveles", 2, 0, 0)
      prizes = Prize.new(1, 1)
      @unused_monsters << (Monster.new("La que redacta en las tinieblas", 2, bad_stuff, prizes, 0))

      #Los hondos
      bad_stuff = BadStuff.new_death("Estos monstruos resultan bastante superficiales y te aburren mortalmente. Estas muerto", true)
      prizes = Prize.new(2, 1)
      @unused_monsters << (Monster.new("Los hondos", 8, bad_stuff, prizes, 0))

      #Semillas Cthulu
      bad_stuff = BadStuff.new_level_number_of_treasures("Pierdes 2 niveles y 2 tesoros ocultos.", 2, 0, 2)
      prizes = Prize.new(2, 1)
      @unused_monsters << (Monster.new("Semillas Cthulu", 4, bad_stuff, prizes, 0))

      #Dameargo
      tvp.clear()
      tvp << :ONEHAND
      bad_stuff = BadStuff.new_level_specific_treasures("Te intentas escaquear. Pierdes una mano visible", 0, tvp, [])
      prizes = Prize.new(2, 1)
      @unused_monsters << (Monster.new("Dameargo", 1, bad_stuff, prizes, 0))

      #Pollipólipo volante
      bad_stuff = BadStuff.new_level_number_of_treasures("Da mucho asquito. Pierdes 3 niveles", 3, 0, 0)
      prizes = Prize.new(1, 1)
      @unused_monsters << (Monster.new("Pollipólipo volante", 3, bad_stuff, prizes, 0))

      #Familia feliz
      bad_stuff = BadStuff.new_death("La familia te atrapa. Estás muerto.", true)
      prizes = Prize.new(4, 1)
      @unused_monsters << (Monster.new("Familia feliz", 1, bad_stuff, prizes, 0))

      #Roboggoth
      tvp.clear()
      tvp << :BOTHHAND
      bad_stuff = BadStuff.new_level_specific_treasures("La quinta directiva primaria te obliga a perder 2 niveles y un tesoro 2 manos visible", 2, tvp, [])
      prizes = Prize.new(2, 1)
      @unused_monsters << (Monster.new("Roboggoth", 8, bad_stuff, prizes, 0))

      #El espia
      tvp.clear()
      tvp. << :HELMET
      bad_stuff = BadStuff.new_level_specific_treasures("Te asusta en la noche. Pierdes un casco visible", 2, tvp, [])
      prizes = Prize.new(1, 1)
      @unused_monsters << (Monster.new("El espía", 5, bad_stuff, prizes, 0))

      #El lenguas
      bad_stuff = BadStuff.new_level_number_of_treasures("Menudo susto te llevas. Pierdes 2 niveles y 5 tesoros visibles", 2, 5, 0)
      prizes = Prize.new(1, 1)
      @unused_monsters << (Monster.new("El lenguas", 20, bad_stuff, prizes, 0))

      #Bicéfalo
      tvp.clear()
      tvp << :BOTHHAND
      tvp << :ONEHAND
      bad_stuff = BadStuff.new_level_specific_treasures("Te faltan manos para tanta cabeza. Pierdes 3 niveles y tus tesoros visibles de las manos.", 3, tvp, [])
      prizes = Prize.new(1, 1)
      @unused_monsters << (Monster.new("Bicéfalo", 20, bad_stuff, prizes, 0))
      
      #El mal indecible impronunciable
      tvp.clear()
      tvp << :ONEHAND
      bad_stuff = BadStuff.new_level_specific_treasures("Pierdes una mano visible.", 0, tvp, []);
      prizes = Prize.new(3, 1)
      @unused_monsters << (Monster.new("El mal indecible impronunciable", 10, bad_stuff, prizes, -2))
      
      #Testigos oculares
      tvp.clear()
      tvp << :ARMOR
      tvp << :BOTHHAND
      tvp << :HELMET
      tvp << :NECKLACE
      tvp << :ONEHAND
      tvp << :SHOE
      bad_stuff = BadStuff.new_level_specific_treasures("Pierdes tus tesoros visibles. Jajaja.", 0, tvp, []);
      prizes = Prize.new(2, 1)
      @unused_monsters << (Monster.new("estigos oculares", 6, bad_stuff, prizes, +2))

      #El gran Cthulhu
      bad_stuff = BadStuff.new_death("Hoy no es tu día de suerte. Mueres.", true);
      prizes = Prize.new(2, 5)
      @unused_monsters << (Monster.new("El gran Cthulhu", 20, bad_stuff, prizes, +4))

      #Serpiente politico
      tvp.clear()
      tvp << :ONEHAND
      bad_stuff = BadStuff.new_level_number_of_treasures("Tu gobierno te recorta 2 niveles.", 2, 0, 0);
      prizes = Prize.new(2, 1)
      @unused_monsters << (Monster.new("Serpiente politico", 8, bad_stuff, prizes, -2))
      
  
      #Felpuggoth
      tvp.clear()
      tvp << :HELMET
      tvp << :ARMOR 
      top.clear()
      top << :BOTHHAND
      top << :ONEHAND
      bad_stuff = BadStuff.new_level_specific_treasures("Pierdes tu casco y tu armadura visible. Pierdes tus manos ocultas.", 2, tvp, top);
      prizes = Prize.new(1, 1)
      @unused_monsters << (Monster.new("Felpuggoth", 2, bad_stuff, prizes, +5))

   
      #Shoggoth
      tvp.clear()
      tvp << :HELMET 
      tvp << :ARMOR  
      top.clear()
      top << :BOTHHAND
      top << :ONEHAND
      bad_stuff = BadStuff.new_level_number_of_treasures("Pierdes 2 niveles.", 2, 0, 0);
      prizes = Prize.new(4, 2)
      @unused_monsters << (Monster.new("Shoggoth", 16, bad_stuff, prizes, -5))
      
   
      #Lolitagooth
      bad_stuff = BadStuff.new_level_number_of_treasures("Pintalabios negro. Pierdes 2 niveles.", 2, 0, 0);
      prizes = Prize.new(1, 1)
      @unused_monsters << (Monster.new("Lolitagooth", 2, bad_stuff, prizes, +3))
 
    end
    
    def shuffle_treasures
      #Ordenar forma aleatoria   unusedTreasures
      @unused_treasures.shuffle!
    end
    
    def shuffle_monsters
      @unused_monsters.shuffle!
    end
   
    
    def shuffle_cultist
      @unused_cultists.shuffle!
    end    
  
    def init_cultist_card_deck

      @unused_cultists << Cultist.new("Sectario 1", 1)
      
      @unused_cultists << Cultist.new("Sectario 2", 2)
             
      @unused_cultists << Cultist.new("Sectario 3", 1)
             
      @unused_cultists << Cultist.new("Sectario 4", 4)
             
      @unused_cultists << Cultist.new("Sectario 5", 1)
             
      @unused_cultists << Cultist.new("Sectario 6", 1)
       
    end 
    
    
    public #METODOS PUBLICOS
    def next_treasure
      if(@unused_treasures.empty?)
        @unused_treasures = @used_treasures    #apuntan al mismo objeto
        @used_treasures = []                #Para que apunte a nueva memoria
        self.shuffle_treasures
      end
      #Muevo la primera carta de tesoro a la baraja de usadas y la devuelvo
      give_treasure_back(@unused_treasures[0])
      @unused_treasures.delete_at(0)
      return @used_treasures.last      
    end
    
    def next_monster
      if(@unused_monsters.empty?)
        @unused_monsters = @used_monsters    #apuntan al mismo objeto
        @used_monsters = []                #Para que apunte a nueva memoria
        shuffle_monsters
      end  
      #Muevo la primera carta de tesoro a la baraja de usadas y la devuelvo
      self.give_monster_back(@unused_monsters[0])
      @unused_monsters.delete_at(0)      
      return @used_monsters.last
    end
    
    def give_treasure_back(t)
      used_treasures << t
    end
    
    def give_monster_back(m)
      used_monsters << m
    end
    
    def init_cards
      init_treasure_card_deck
      init_monster_card_deck
      init_cultist_card_deck
      shuffle_treasures 
      shuffle_monsters
      shuffle_cultist      
    end
    
    def next_cultist    #no es necesario devolver las cartas al mazo
      el_next = @unused_cultists.first
      @unused_cultists.delete_at(0)
      return el_next
    end
       
  end
end